package com.lyl.serviceresume.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lyl.commonutils.JwtUtils;
import com.lyl.commonutils.R;
import com.lyl.serviceresume.entity.ResumeUser;
import com.lyl.serviceresume.service.ResumeService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 雷艳玲
 * @since 2022-07-21
 */
@RestController
@RequestMapping("/serviceresume/resume")
public class ResumeUserController {

    @Autowired
    ResumeService resumeService;



    @ApiOperation(value = "获取简历列表根据老师id")
    @PostMapping("{page}/{limit}")
    public R pageQuery(
            HttpServletRequest request,
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Long page,

            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable Long limit,

            @ApiParam(name = "courseQuery", value = "查询对象", required = false)
                    ResumeUser resumeUserQuery){

        // 获取登录的人的id
        Long tid = new Long(JwtUtils.getUserIdFromToken(request.getHeader("token"),"id"));

        resumeUserQuery.setTeacherId(tid);

        Page<ResumeUser> pageParam = new Page<>(page, limit);

        resumeService.pageQuery(pageParam, resumeUserQuery);
        List<ResumeUser> records = pageParam.getRecords();

        long total = pageParam.getTotal();

        return  R.ok().data("total", total).data("rows", records);
    }



}

